#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot = 1;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
int dep[N], sz[N], fa[N], son[N], top[N];
int pos[N], a[N], b[N], num;
void dfs(int u, int fu, int w) {
  dep[u] = dep[fu] + 1;
  sz[u] = 1;
  fa[u] = fu;
  a[u] = w;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    int w = W[i];
    dfs(v, u, w);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int fu, int t) {
  top[u] = t;
  pos[u] = ++num;
  b[num] = a[u];
  if (!son[u]) return;
  dfs2(son[u], u, t);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu || v == son[u]) continue;
    dfs2(v, u, v);
  }
}
struct Node {
  int sum, mn, mx, tag;
} tr[N << 2];

Node merge(Node x, Node y) {
  Node res;
  res.sum = x.sum + y.sum;
  res.mn = min(x.mn, y.mn);
  res.mx = max(x.mx, y.mx);
  res.tag = 0;
  return res;
}
void pushup(int p) { tr[p] = merge(tr[p << 1], tr[p << 1 | 1]); }
void build(int p, int l, int r) {
  if (l == r) {
    tr[p] = Node{b[l], b[l], b[l], 0};
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void addtag(int p, int l, int r) {
  tr[p].tag ^= 1;
  swap(tr[p].mn, tr[p].mx);
  tr[p].sum *= -1;
  tr[p].mn *= -1;
  tr[p].mx *= -1;
}
void pushdown(int p, int l, int r) {
  if (tr[p].tag) {
    int mid = (l + r) >> 1;
    addtag(p << 1, l, mid);
    addtag(p << 1 | 1, mid + 1, r);
    tr[p].tag = 0;
  }
}
void change(int x, int d, int p, int l, int r) {
  if (l == r) {
    tr[p] = Node{d, d, d, 0};
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid)
    change(x, d, p << 1, l, mid);
  else
    change(x, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(p, l, r);
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, p << 1, l, mid);
  if (R > mid) update(L, R, p << 1 | 1, mid + 1, r);
  pushup(p);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid) {
    return merge(query(L, R, p << 1, l, mid),
                 query(L, R, p << 1 | 1, mid + 1, r));
  } else if (L <= mid)
    return query(L, R, p << 1, l, mid);
  else
    return query(L, R, p << 1 | 1, mid + 1, r);
}
void update(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    update(pos[top[u]], pos[u], 1, 1, n);
    u = fa[top[u]];
  }
  if (u == v) return;
  if (dep[u] > dep[v]) swap(u, v);
  update(pos[u] + 1, pos[v], 1, 1, n);
}
const int INF = 1e9;
Node query(int u, int v) {
  Node res{0, INF, -INF, 0};
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    Node x = query(pos[top[u]], pos[u], 1, 1, n);
    res = merge(res, x);
    u = fa[top[u]];
  }
  if (u == v) return res;
  if (dep[u] > dep[v]) swap(u, v);
  res = merge(res, query(pos[u] + 1, pos[v], 1, 1, n));
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    u++, v++;
    add(u, v, w), add(v, u, w);
  }
  dfs(1, 0, 0);
  dfs2(1, 0, 1);
  build(1, 1, n);
  cin >> m;
  while (m--) {
    string op;
    int x, y;
    cin >> op >> x >> y;
    x++, y++;
    if (op == "SUM") {
      cout << query(x, y).sum << endl;
    } else if (op == "MAX") {
      cout << query(x, y).mx << endl;
    } else if (op == "MIN") {
      cout << query(x, y).mn << endl;
    } else if (op == "C") {
      x--, y--;
      int u = ver[x * 2];
      int v = ver[x * 2 + 1];
      x = dep[u] > dep[v] ? u : v;
      change(pos[x], y, 1, 1, n);
    } else {
      update(x, y);
    }
  }
  return 0;
}